<body class="app" data-ad="true">
<?php $CDN= $this->CommonHelper()->imageDomain();?>
<section class="app-content">
	<section class="page page-index noline" data-plugin-type="info_front">

        <article class="shop-message">
            <dl>
                <dt class="shop-l">
                    <img src="<?php echo "{$CDN}{$this->orgInfo['org_thumb_image']}";?>">
                </dt>
                <dd>
                    <h2 class="sp-title"><?php echo $this->orgInfo['org_title'];?>配餐/商户<span><?php echo $this->orgInfo['org_level'];?></span></h2>
                    <!--<div class="sp-des">副标题副标题副标题副标题副标题副标题副标题副标题副标题副标题 </div>-->
                    <div class="sp-notice" id="marquee">
                        <div><span>公告：<?php echo $this->orgInfo['org_advice'];?></span></div>
                    </div>
                </dd>
            </dl>
            <a class="ico-arr ico-search-grey btn-shop-search" href="/index/search"></a>
            <a class="btn-collect" href="javascript:collect('<?php echo $this->org_id;?>');">收 藏</a>
        </article>
        <div class="bw shop-tab">
            <ul class="prod-nav zoom">
                <li><a href="<?php echo "/organization/vMerchant/{$this->org_id}" ?>" class="on">商户</a></li>
                <li><a href="<?php echo "/organization/vSeller/{$this->org_id}"?>">商 家</a></li>
            </ul>
        </div>

        <div class="shop-ct-block" style="">
            <!-- 左边菜单-->
            <div class="sp-l-nav sp-shop-l-nav">
                <ul>
                   <?php if(count($this->category)>0):?>
                   <?php $i=1;?>
                   <?php foreach($this->category as $cateKey=>$categroyItem):?>
                   <?php
                   		if(1==$i){
                   			$class="class='on'";
                   		}else{
                   			$class="";
                   		}
                   		$i++;
                   		$id="id='{$cateKey}'";
                   		$_num=count($categroyItem['productList'][1])+count($categroyItem['productList'][2])+count($categroyItem['productList'][3]);
                   		if($_num>0){
                   			$_icon="<i class='new-tips'>{$_num}</i>";
                   		}else{
                   			$_icon="";
                   		}
                   		//print_r($_num);
                   ?>
                    <li <?php echo $id;?>  <?php echo $class; ?>><a href="javascript:;"><?php echo $categroyItem['week']; ?><span><?php echo $categroyItem['day']; ?></span><?php echo $_icon;?></a></li>
                   <?php endforeach;?>
                   <?php endif;?>
                </ul>
            </div>
            <!-- 右边内容-->
            <div class="sp-r-ct">
                <div class="r-nav-time">
                    <div class="r-nav-time-wrap">
                        <a href="#item01" class="on">早餐</a>
                        <a href="#item02">中餐</a>
                        <a href="#item03">晚餐</a>
                    </div>

                </div>
                <h3 class="sp-tit-time">早餐</h3>
                <div name="item01" class="item-wrap-r" id="item01">
                	<?php if(count($this->category)>0):?>
                	<?php foreach ($this->category as $cateKey => $categoryItem):?>
                	<?php if(count($categoryItem['productList'][1])>0):?>
					<?php foreach ($categoryItem['productList'][1] as $proKey => $productItem):?>
					<input id="proImgBig_<?php echo $productItem['product_id'];?>" type="hidden"  value="<?php echo "{$CDN}{$productItem['product_big_image']}";?>" >
                    <dl class="sp-item <?php echo $cateKey;?>">
                        <dt><a href="javascript:suyuan('<?php echo $categoryItem['day'];?>','<?php echo $productItem['product_id'];?>');" class="sp-btn-origin"><img src="<?php echo "{$CDN}{$productItem['product_thumb_image']}";?>"></a></dt>
                        <dd>
                            <h3><a href="javascript:suyuan('<?php echo $categoryItem['day'];?>','<?php echo $productItem['product_id'];?>');" class="sp-btn-origin"><?php echo $productItem['product_name'];?></a></h3>
                            <h4>简介：<?php echo $productItem['product_description'];?></h4>
                            <h5>规格：5kg／袋</h5>
                            <p class="price">￥<span id="proPrice_<?php echo $productItem['product_id'];?>" class="p-num"><?php echo $productItem['product_price'];?></span></p>
                            <div id="cal_<?php echo "{$categoryItem['day']}_{$productItem['product_id']}";?>" class="ope-line">
                                <a class="btn-ope btn-ope-minus" href="javascript:proMinus('<?php echo $productItem['product_id'];?>');"></a><span class="sp-ope-num">0</span><a class="btn-ope btn-ope-plus" href="javascript:proAdd('<?php echo $productItem['product_id'];?>');"></a>
                            </div>
                        </dd>
                    </dl>
                    <?php endforeach;?>
                    <?php endif;?>
                	<?php endforeach;?>
                	<?php endif;?>
                </div>

                <h3 class="sp-tit-time">中餐</h3>
                <div name="item02" class="item-wrap-r" id="item02">
                    <?php if(count($this->category)>0):?>
                	<?php foreach ($this->category as $cateKey => $categoryItem):?>
                	<?php if(count($categoryItem['productList'][2])>0):?>
                	<?php //var_dump($categoryItem['data']);die;?>
					<?php foreach ($categoryItem['productList'][2] as $proKey => $productItem):?>
					<input id="proImgBig_<?php echo $productItem['product_id'];?>" type="hidden"  value="<?php echo "{$CDN}{$productItem['product_big_image']}";?>" >
                    <dl class="sp-item <?php echo $cateKey; ?>">
                        <dt><a href="javascript:suyuan('<?php echo $categoryItem['day'];?>','<?php echo $productItem['product_id'];?>');" class="sp-btn-origin"><img src="<?php echo "{$CDN}{$productItem['product_thumb_image']}";?>"></a></dt>
                        <dd>
                            <h3><a href="javascript:suyuan('<?php echo $categoryItem['day'];?>','<?php echo $productItem['product_id'];?>');" class="sp-btn-origin"><?php echo $productItem['product_name'];?></a></h3>
                            <h4>简介：<?php echo $productItem['product_description'];?></h4>
                            <h5>规格：5kg／袋</h5>
                            <p class="price">￥<span id="proPrice_<?php echo $productItem['product_id'];?>" class="p-num"><?php echo $productItem['product_price'];?></span></p>
                            <div id="cal_<?php echo "{$categoryItem['day']}_{$productItem['product_id']}";?>" class="ope-line">
                                <a class="btn-ope btn-ope-minus" href="javascript:proMinus('<?php echo $productItem['product_id'];?>');"></a><span class="sp-ope-num">0</span><a class="btn-ope btn-ope-plus" href="javascript:proAdd('<?php echo $productItem['product_id'];?>');"></a>
                            </div>
                        </dd>
                    </dl>
                    <?php endforeach;?>
                    <?php endif;?>
                	<?php endforeach;?>
                	<?php endif;?>
                </div>

                <h3 class="sp-tit-time">晚餐</h3>
                <div name="item03" class="item-wrap-r" id="item03">
                    <?php if(count($this->category)>0):?>
                	<?php foreach ($this->category as $cateKey => $categoryItem):?>
                	<?php if(count($categoryItem['productList'][3])>0):?>
					<?php foreach ($categoryItem['productList'][3] as $proKey => $productItem):?>
					<input id="proImgBig_<?php echo $productItem['product_id'];?>" type="hidden"  value="<?php echo "{$CDN}{$productItem['product_big_image']}";?>" >
                    <dl class="sp-item <?php echo $cateKey; ?>">
                        <dt><a href="javascript:suyuan('<?php echo $categoryItem['day'];?>','<?php echo $productItem['product_id'];?>');" class="sp-btn-origin"><img src="<?php echo "{$CDN}{$productItem['product_thumb_image']}";?>"></a></dt>
                        <dd>
                            <h3><a href="javascript:suyuan('<?php echo $categoryItem['day'];?>','<?php echo $productItem['product_id'];?>');" class="sp-btn-origin"><?php echo $productItem['product_name'];?></a></h3>
                            <h4>简介：<?php echo $productItem['product_description'];?></h4>
                            <h5>规格：5kg／袋</h5>
                            <p class="price">￥<span id="proPrice_<?php echo $productItem['product_id'];?>" class="p-num"><?php echo $productItem['product_price'];?></span></p>
                            <div id="cal_<?php echo "{$categoryItem['day']}_{$productItem['product_id']}";?>" class="ope-line">
                                <a class="btn-ope btn-ope-minus" href="javascript:proMinus('<?php echo $productItem['product_id'];?>');"></a><span class="sp-ope-num">0</span><a class="btn-ope btn-ope-plus" href="javascript:proAdd('<?php echo $productItem['product_id'];?>');"></a>
                            </div>
                        </dd>
                    </dl>
                    <?php endforeach;?>
                    <?php endif;?>
                	<?php endforeach;?>
                	<?php endif;?>
                </div>

            </div>
        </div>

	</section>

    <div class="total-bar" style="bottom: 95px;">
		<form id="orderForm" action="/order/index" method='post'>
	        <input id="org_id" name="org_id" type="hidden" value="<?php echo $this->org_id;?>">
	        <input id="proList" name="proList" type="hidden" value="">
	        <input id="numList" name="numList" type="hidden" value="">
			<a class="btn-yel02 btn-statement" href="javascript:goOrder();">去结算</a>
			<span class="t-num">件数<i id="total_num">0</i></span>
			<span class="t-price">合计  ¥ <i id="total_price">0.00</i></span>
        </form>
    </div>
    <!-- 底部menu-->
    <?php echo $this->partial('public/menu.phtml'); ?>
</section>
<div class="bgMask"></div>
<div class="popup popup-shop">
    <img class="pop-s-img" src="/mobile/images/temp/pop-shop.jpg">
    <div class="pop-s-ct">
        <h3 class="pop-s-title">商品／套餐A</h3>
        <div class="pop-s-des">鸿益配餐精制的鱼香肉丝套餐全部采用有机原 材料制作而成，营养美味，健康可口...</div>
        <h3 class="pop-s-material">用 料</h3>
        <div class="info-ct">
            <ul class="pop-s-uladd">
            </ul>
        </div>
        <div id="pop-purchase">
        <a href="javascript:;" class="btn-buy mb20">购 买</a>
        </div>
    </div>

</div>


<script type="text/javascript">
$(function(){
	$(".sp-r-ct dl").hide();
	$(".sp-r-ct dl:first").show();
	$(".sp-l-nav li").click(function(){
		$(".sp-r-ct dl").hide();
		$(".sp-l-nav li").removeClass("on");
		$(this).addClass("on");
		var _class="."+$(this).attr("id");
		$(_class).show();
	});
})
                   
$(function () {
    var myH = document.body.clientHeight-500;//去掉头部及页面底部固定内容
    $('.sp-shop-l-nav').height(myH);

    $('.r-nav-time-wrap a').each(function(i){
        $(this).click(function() {
            $(this).addClass('on').siblings('a').removeClass('on');
            $('.item-wrap-r').eq(i).css('padding-top', '378px').siblings('.item-wrap-r').css('padding-top', '0');
        });
    })


  /**  $('.sp-r-ct .sp-btn-origin').click(function(){console.log(111)
        $('.bgMask,.popup-shop').show();
    })
**/
    $('.bgMask').click(function(){
        $('.bgMask,.popup-shop').hide();
    })
});

//溯源显示
var isPost = false;
function suyuan(day,proId){
    $('.pop-s-img').attr("src",$("#proImgBig_"+proId).val());
    $('.pop-s-title').text($("#proName_"+proId).text());
    $('.pop-s-des').text($("#proDes_"+proId).text());
    if(!isPost){
        isPost = true;
        $.ajax({
            url: '/organization/material',
            type: 'post',
            data: {
                'product_id': proId,
                },
            dataType: 'json',
            timeout: 200000,
            success: function (json) {
                isPost = false;
                if (json.result) {
                    var html="";
                    var material_id = "";
                    for(var i=0;i<json.data.length;i++){
                        material_id = json.data[i].material_id;
                        html += '<li><span>'+ json.data[i].material_name +'</span><a href="javascript:;" class="btn-s-origin">溯 源</a></li>';
                    }
                    var cur_obj = $("#cal_"+day+"_"+proId);
                    var cur_num_obj = cur_obj.find('.sp-ope-num');
                    var t_num = parseInt(cur_num_obj.html())+1;
                    cur_num_obj.html(t_num);
                    if(t_num>0){
                        cur_obj.find('.btn-ope-minus,.sp-ope-num').css('visibility','visible');
                    }
                    var purchaseHtml='<a href="javascript:proAdd('+proId+');" class="btn-buy mb20">购 买</a>';
                    $("#pop-purchase").html(purchaseHtml);
                    $('.pop-s-uladd').html(html);
                    $('.popup-shop').show();
                } else {
                    alert(json.reason);
                }
            },
            error: function (err) {
                isPost = false;
                alert('请求超时，请重新操作');
                return false; 
            }
        });
    }
    
    $('.bgMask').show();
}

var productList =  new Array();
var numList =  new Array();
//增加商品
function proAdd(proId){
    var total_num = parseFloat($('#total_num').text()) + 1;
    var total_price = parseFloat($('#total_price').text()) + parseFloat($("#proPrice_"+proId).text());
    $('#total_num').text(total_num);
    $('#total_price').text(toDecimal2(total_price));
    var flg =true;
    for (var i=0 ; i < productList.length ; ++i ){
        if(productList[i] == proId){
            numList[i] = numList[i] + 1;
            flg = false;
        }
    } 
    if(flg){
        productList.push(proId);
        numList.push(1);
    }
    $('.bgMask,.popup-shop').hide();
}
//减少商品
function proMinus(proId){
    var total_num = parseFloat($('#total_num').text()) - 1;
    var total_price = parseFloat($('#total_price').text()) - parseFloat($("#proPrice_"+proId).text());
    $('#total_num').text(total_num);
    $('#total_price').text(toDecimal2(total_price));
    for (var i=0 ; i < productList.length ; ++i ){
        if(productList[i] == proId){
            numList[i] = numList[i] - 1;
            if(numList[i] == 0){
                delete productList[i];
                delete numList[i];
            }
        }
    }
}
//去结算
function goOrder(){
    var total_num = parseFloat($('#total_num').text());
    if(total_num == 0){
        alert("请先选择商品！");
        return false;
    }
    $("#proList").val(productList.join("|"));
    $("#numList").val(numList.join("|"));
    $("#orderForm").submit();
}
//收藏
function collect(orgId){
    if(!isPost){
        isPost = true;
        $.ajax({
            url: '/organization/collect',
            type: 'post',
            data: {
                'orgId': orgId,
                },
            dataType: 'json',
            timeout: 200000,
            success: function (json) {
                isPost = false;
                alert(json.reason);
            },
            error: function (err) {
                isPost = false;
                alert('请求超时，请重新操作');
                return false; 
            }
        });
    }
}
</script>
